package com.example.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.pojo.User.InvitedUserDTO;
import com.example.demo.pojo.User.User;
import com.example.demo.pojo.User.UserInfoDTO;
import com.example.demo.pojo.vip.VipUserDto;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User> {

    @Select("SELECT u.id, u.user_name, u.nick_name, u.real_name, u.email, u.phone_number, u.id_card_number, " +
            "u.School_address, u.educational_background, u.major, u.home_address, u.contact_address, " +
            "u.role,u.header_url,r.real_name_status " +
            "FROM user u " +
            "LEFT JOIN real_name_authentication r ON u.id = r.user_id " +
            "WHERE u.user_name = #{userName}")
    UserInfoDTO getUserInfo(@Param("userName") String userName);

    @Select("SELECT u.nick_name AS nickName, u.real_name AS realName, u.header_url AS headerUrl, v.start_time AS startTime, v.end_time AS endTime, v.status, v.type, v.remark " +
            "FROM user u " +
            "JOIN vip_dto v ON u.id = v.user_id " +
            "WHERE v.end_time BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 7 DAY)")
    @Results({
            @Result(property = "nickName", column = "nickName"),
            @Result(property = "realName", column = "realName"),
            @Result(property = "headerUrl", column = "headerUrl"),
            @Result(property = "startTime", column = "startTime"),
            @Result(property = "endTime", column = "endTime"),
            @Result(property = "status", column = "status"),
            @Result(property = "type", column = "type"),
            @Result(property = "remark", column = "remark")
    })
    List<VipUserDto> getExpireVipUsers();
    @Select("SELECT id, real_name, School_address, major " +
            "FROM user " +
            "WHERE LOWER(CONVERT(real_name USING utf8mb4)) LIKE LOWER(CONVERT(CONCAT('%', #{realName}, '%') USING utf8mb4))")
    List<InvitedUserDTO> getInvitedUser(@Param("realName") String realName);

}
